﻿<%@ Page Language="C#" %>

<%
    var rootPath = this.Server.MapPath("../../").TrimEnd('\\');
    var results = new ArrayList();

    Happy.Utils.DirectoryUtil.PreOrderTraverse(rootPath, x => true, x =>
        {
            if (x == rootPath)
            {
                return;
            }

            var name = System.IO.Path.GetFileName(x);
            var parentId = System.IO.Path.GetDirectoryName(x).Remove(0, rootPath.Length);

            results.Add(new
            {
                Id = parentId + "\\" + name,
                Name = name,
                ParentId = parentId == String.Empty ? "\\" : parentId,
                leaf = System.IO.Path.HasExtension(x)
            });
        });

%>

<%= Newtonsoft.Json.JsonConvert.SerializeObject(new { items = results }) %>